<template>
  <div>
    <table-ext :columns="columns" :searchForm="searchForm" :config="config" ref="tableExt">
    </table-ext>
  </div>
</template>
<script>
  import TableExt from '@/components/common/table-ext/table-ext.vue';
  import TableIcon from '@/components/common/table-ext/table-icon';
  export default {
    // 引入自定义表格组件
    components: {
      'table-ext': TableExt
    },
    data() {
      return {
        config: { // 页面共通配置
          title: '专家打分', //页面标题
          isPage: true, //是否分页
          isNo: false, //是否显示序号
          selection: false, //是否显示复选框
          align:'center',//表格居中
          crudMapping: { // CRUD方法
            query: {
              url: this.lib.config.host.vendorDlv + "/vendormgt/dlv/factoryInspect/score/queryScoreItem",
              method: 'post'
            }
          }
        },
        // 查询表单配置
        searchForm: [
        { // 查询表单配置
          label: '采购组织', 
          key: 'purOrgId', 
          type: 'select',
          dict:{
            url:this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/'+this.getCurrUserId(),
            method:'get',
            label:'purOrgName',
            value:'id'
          }
        }, {
          label: '采购组',
          key: 'purGroupId',
          type: 'select',
          dict:{
            url:this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/{purOrgId}',
            method:'post',
            label:'purGroupName',
            value:'id'
          }
        }, {
          label: '单据号',
          key: 'inspectNo',
          type: 'input'
        }, {
          label: '标题',
          key: 'title',
          type: 'input'
        }, {
          label: '供应商编码',
          key: 'vendorCode',
          type: 'input'
        }, {
          label: '供应商名称',
          key: 'vendorName',
          type: 'input'
        }, {
          label: '品类',
          key: 'categoryCode',
          type: 'select-tree'
        }, {
          label: '发布状态',
          key: 'publishStatus',
          type: 'select',
          dict: [{
            value: '0',
            label: '未发布'
          }, {
            value: '1',
            label: '已发布'
          }]
        }, {
          label: '评估岗位',
          key: 'sysStationName',
          type: 'input'
        }, {
          label: '评估类型',
          key: 'inspectType',
          type: 'select',
          dict: [{
            value: '1',
            label: '初审'
          }, {
            value: '2',
            label: '年度复审'
          }]
        }, {
          label: '结论',
          key: 'resultFlag',
          type: 'select',
          dict: [{
            value: '-1',
            label: '不合格'
          }, {
            value: '1',
            label: '合格'
          }]
        }, {
          label: '完成状态',
          key: 'completeStatus',
          type: 'select',
          dict: [{
            value: '0',
            label: '未完成'
          }, {
            value: '1',
            label: '已完成'
          }, {
            value: '2',
            label: '部分完成'
          }]
        }, {
          label: '反馈状态',
          key: 'feedbackStatus',
          type: 'select',
          dict: [{
            value: '0',
            label: '待反馈'
          }, {
            value: '1',
            label: '已反馈'
          }, {
            value: '3',
            label: '待反馈'
          }]
        }, {
          label: '验证状态',
          key: 'checkStatus',
          type: 'select',
          dict: [{
            value: '0',
            label: '未验证'
          }, {
            value: '3',
            label: '待验证'
          }, {
            value: '1',
            label: '验证通过'
          }, {
            value: '-1',
            label: '验证驳回'
          }]
        }],
        // 表格列定义
        columns: [{
            width: '120px',
            label: '操作', // 表格header
            render: (createElement, params) => { // 动态渲染，click事件示例
              let _this = this;

              var btnArrs = [];
              btnArrs.push(createElement('el-button', {
                  props: {
                    type: 'text',
                  },
                  on: {
                    click() {                
                    //  _this.setCurrenter({
                    //    factoryInspectItemId:params.row.dlvVendorId,
                    //    factoryInspectId:params.row.factoryInspect.id
                    //  });
                     _this.setCurrenter(params.row.id)
                    }
                  }
                }, '查看'));
              return createElement('div', {}, btnArrs);
            }
          },
          {
            label: '采购组织',
            key: 'factoryInspect.purOrgName',
            width: '120px'
          },
          {
            label: '采购组',
            key: 'factoryInspect.purGroupName',
            width: '120px'
          },
          {
            label: '单据号',
            key: 'factoryInspect.inspectNo',
            width: '180',
            render: (createElement, params) => { // 动态渲染，click事件示例
              let _this = this;
              return createElement('div', {}, [createElement('a', {
                  style: {
                    color: '#409EFF',
                    cursor: 'pointer'
                  },
                on: {
                  click() {
                    _this.setCurrent(params.row.dlvFactoryInspectId);
                  }
                }
              }, params.row.factoryInspect.inspectNo)]);
            }
          },
          {
            label: '标题',
            key: 'factoryInspect.title',
            width:'200px'
          }, {
            label: '评估类型',
            key: 'factoryInspect.inspectType',
            render:(createElement, params)=>{ //动态渲染, 字典表示例
              let inspectType =params.row.factoryInspect.inspectType;
              if (inspectType == 1) {
                return createElement('div', '初审');
              }else if(inspectType == 2){
                return createElement('div', '年度复审');
              }else{
                return createElement('div', '');
              }
            }            
          }, {
            label: '品类',
            key: 'factoryInspect.categoryName',
             width:'200px'
          }, {
            label: '供应商编码',
            key: 'vendorCode',
            width: '120'
          }, {
            label: '供应商名称',
            key: 'vendorName',
            width: '250'
          }, {
            label: '评分岗位',
            key: 'sysStationName',
             width: '240'
          }, {
            label: '评估维度',
            key: 'assessDictItemName',
             width: '100'
          }, {
            label: '发布状态',
            key: 'publishStatus',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.publishStatus,
                  titles: [{
                    status: 0,
                    title: '未发布'
                  }, {
                    status: 1,
                    title: '已发布'
                  }]
                }
              });
            }
          }, {
            label: '发布日期',
            key: 'factoryInspect.checkTime',
            width: '120'
          }, {
            label: '评估分数',
            key: 'totalPoints'
          }, {
            label: '结论',
            key: 'resultFlag',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.resultFlag,
                  titles: [{
                    status: -1,
                    title: '不合格'
                  }, {
                    status: 1,
                    title: '合格'
                  }]
                }
              });
            }            
          }, {
            label: '是否整改',
            key: 'improveFlag',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.improveFlag,
                  titles: [{
                    status: 0,
                    title: '否'
                  }, {
                    status: 1,
                    title: '是'
                  }]
                }
              });
            }
          }, {
            label: '反馈状态',
            key: 'feedbackStatus',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.feedbackStatus,
                  titles: [{
                    status: 0,
                    title: '未开始'
                  }, {
                    status: 1,
                    title: '已反馈'
                  }, {
                    status: 3,
                    title: '待反馈'
                  }]
                }
              });
            }
          }, {
            label: '验证状态',
            key: 'checkStatus',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.checkStatus,
                  titles: [{
                    status: 0,
                    title: '未验证'
                  }, {
                    status: 1,
                    title: '验证通过'
                  }, {
                    status: -1,
                    title: '驳回'
                  }, {
                    status: 3,
                    title: '待验证'
                  }]
                }
              });
            }
          },
          // {
          //   label: '作废状态',
          //   key: 'factoryInspect.abolishStatus',
          //   render: (createElement, params) => { //动态渲染, 字典表示例
          //     return createElement(TableIcon, {
          //       props: {
          //         flag: params.row.factoryInspect.abolishStatus,
          //         titles: [{
          //           status: 0,
          //           title: '未作废'
          //         }, {
          //           status: 1,
          //           title: '已作废'
          //         }]
          //       }
          //     });
          //   }
          // }, 
          {
            label: '完成状态',
            key: 'completeStatus',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.completeStatus,
                  titles: [{
                    status: 0,
                    title: '未完成'
                  }, {
                    status: 1,
                    title: '已完成'
                  }, {
                    status: 2,
                    title: '部分完成'
                  }]
                }
              });
            }
          }
        ]
      };
    },
    mounted() { // VUE页面渲染之后调用的方法

    },
    methods: {
      // 批量删除
      batchDelete() {
        let checkRows = this.$refs['tableExt'].multipleSelection;
        checkRows.map(item => {
          this.checkIds.push(item.id);
        });
        this.securityPost(this.lib.config.host.vendorMgt + '/vendormgt/vsp/registvendor/delete', this.checkIds)
          .then((response) => {
            this.$refs['tableExt'].refreshTable();
          })
          .catch((error) => {
            console.log(error);
          });
        this.checkIds = []
      },
      //点击单号跳转到新页面
      setCurrent(dlvFactoryInspectId){
        window.open('/FactoryInspectItem?id='+dlvFactoryInspectId)
      },
      //点击查看评分跳转到新页面
      setCurrenter(id){
        window.open('/LookScore?id='+id)
      }
      // setCurrenter({
      //   factoryInspectItemId,
      //   factoryInspectId
      // }) {
      //   window.open(`/LookScore?factoryInspectItemId=${factoryInspectItemId}&factoryInspectId=${factoryInspectId}`)
      // }
    }
  }

</script>
